package clone;

import sun.management.resources.agent_it;

//此时A实现了Cloneable接口，就具备了可复制的能力
public class A implements Cloneable{
    private C c=new C();
    @Override
    protected A clone() throws CloneNotSupportedException {
        A a= (A)super.clone();
        c=c.clone();
        return a;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        A a=new A();
        A b=a.clone();
        b.c.num=100;//浅拷贝
        System.out.println(a.c.num);
        Object obj=new A();
    }
}
class C implements Cloneable {
    int num;

    @Override
    protected C clone() throws CloneNotSupportedException {
        return (C)super.clone();
    }
}